/**
  ******************************************************************************
  * @file    w32f006_acmp.h
  * @author  WeiLink Technology
  * @version V1.0.1
  * @date    09/01/2020
  * @brief   This file contains all the functions prototypes for the ADC firmware 
  *          library
  ******************************************************************************
  * @attention
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, WeiLink Technology SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT WeiLink Technology</center></h2>
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __W32F006_ACMP_H
#define __W32F006_ACMP_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "w32f006.h"

/** @addtogroup W32F006_StdPeriph_Driver
  * @{
  */

/** @addtogroup ACMP
  * @{
  */

/* Exported types ------------------------------------------------------------*/

/** 
  * @brief  ACMP Init structure definition
  */
typedef struct
{
	uint32_t ACMP_NegativeSelect;		    /*!< Selects the source of negative pole.
                                            This parameter can be a value of @ref ACMP_Negative_Select */

	uint32_t ACMP_PositiveSelect;           /*!< Selects the source of positive pole.
                                            This parameter can be a value of @ref ACMP_Positive_Select */

	uint32_t ACMP_Hysteresis;               /*!< Selects ACMP hysteresis.
                                            This parameter can be a value of @ref ACMP_Hysteresis */

	uint32_t ACMP_Output;		            /*!< Selects the state of Output.
                                            This parameter can be a value of @ref ACMP_Output_State */
    
    uint32_t ACMP_CLKDIV;                   /*!< Selects clock div.
                                            This parameter can be a value of @ref ACMP_Clock_Div */
    
}ACMP_InitTypeDef;

/* Exported constants --------------------------------------------------------*/

/** @defgroup ACMP_Exported_Constants
  * @{
  */ 
#define ACMP0                               ((uint32_t)0xDCDC0000)
#define ACMP1                               ((uint32_t)0xDCDC0010)
#define IS_ACMP_ALL_PERIPH(PERIPH)          (((PERIPH) == ACMP0) || ((PERIPH) == ACMP1))

#define OPA0                                ((uint32_t)0xDCDC0000)
#define OPA1                                ((uint32_t)0xDCDC0010)
#define IS_OPA_ALL_PERIPH(PERIPH)           (((PERIPH) == OPA0) || ((PERIPH) == OPA1))

/** @defgroup ACMP_Negative_Select
  * @{
  */
#define	ACMP_NEGATIVE_SELECT_PIN0_1                 ((uint32_t)0x00000000)
#define	ACMP_NEGATIVE_SELECT_PIN0_2                 ((uint32_t)0x00000010)
#define	ACMP_NEGATIVE_SELECT_PIN0_3                 ((uint32_t)0x00000020)
#define	ACMP_NEGATIVE_SELECT_PIN0_4                 ((uint32_t)0x00000030)
#define	ACMP_NEGATIVE_SELECT_PIN0_5                 ((uint32_t)0x00000040)
#define	ACMP_NEGATIVE_SELECT_PIN0_6                 ((uint32_t)0x00000050)
#define	ACMP_NEGATIVE_SELECT_PIN0_7                 ((uint32_t)0x00000060)
#define	ACMP_NEGATIVE_SELECT_PIN1_0                 ((uint32_t)0x00000070)
#define	ACMP_NEGATIVE_SELECT_R                      ((uint32_t)0x00000080)
#define	ACMP_NEGATIVE_SELECT_TEMP                   ((uint32_t)0x00000090)
#define	ACMP_NEGATIVE_SELECT_VREF_1P25V             ((uint32_t)0x000000A0)
#define	ACMP_NEGATIVE_SELECT_ADC_VREF               ((uint32_t)0x000000B0)
#define	ACMP_NEGATIVE_SELECT_CORE_LDO               ((uint32_t)0x000000C0)


#define IS_ACMP_NEGATIVE_SELECT(SELECT)    		    (((SELECT) == ACMP_NEGATIVE_SELECT_PIN0_1)  || \
                                                     ((SELECT) == ACMP_NEGATIVE_SELECT_PIN0_2)  || \
                                                     ((SELECT) == ACMP_NEGATIVE_SELECT_PIN0_3)  || \
                                                     ((SELECT) == ACMP_NEGATIVE_SELECT_PIN0_4)  || \
                                                     ((SELECT) == ACMP_NEGATIVE_SELECT_PIN0_5)  || \
                                                     ((SELECT) == ACMP_NEGATIVE_SELECT_PIN0_6)  || \
                                                     ((SELECT) == ACMP_NEGATIVE_SELECT_PIN0_7)  || \
                                                     ((SELECT) == ACMP_NEGATIVE_SELECT_PIN1_0)  || \
                                                     ((SELECT) == ACMP_NEGATIVE_SELECT_R)       || \
                                                     ((SELECT) == ACMP_NEGATIVE_SELECT_TEMP)    || \
                                                     ((SELECT) == ACMP_NEGATIVE_SELECT_VREF_1P25V)  || \
                                                     ((SELECT) == ACMP_NEGATIVE_SELECT_ADC_VREF)    || \
                                                     ((SELECT) == ACMP_NEGATIVE_SELECT_CORE_LDO))
/**
  * @}
  */ 

/** @defgroup ACMP_Positive_Select
  * @{
  */
#define	ACMP_POSITIVE_SELECT_PIN0_1                 ((uint32_t)0x00000000)
#define	ACMP_POSITIVE_SELECT_PIN0_2                 ((uint32_t)0x00000100)
#define	ACMP_POSITIVE_SELECT_PIN0_3                 ((uint32_t)0x00000200)
#define	ACMP_POSITIVE_SELECT_PIN0_4                 ((uint32_t)0x00000300)
#define	ACMP_POSITIVE_SELECT_PIN0_5                 ((uint32_t)0x00000400)
#define	ACMP_POSITIVE_SELECT_PIN0_6                 ((uint32_t)0x00000500)
#define	ACMP_POSITIVE_SELECT_PIN0_7                 ((uint32_t)0x00000600)
#define	ACMP_POSITIVE_SELECT_PIN1_0                 ((uint32_t)0x00000700)

#define IS_ACMP_POSITIVE_SELECT(SELECT)             (((SELECT) == ACMP_POSITIVE_SELECT_PIN0_1) || \
                                                     ((SELECT) == ACMP_POSITIVE_SELECT_PIN0_2) || \
                                                     ((SELECT) == ACMP_POSITIVE_SELECT_PIN0_3) || \
                                                     ((SELECT) == ACMP_POSITIVE_SELECT_PIN0_4) || \
                                                     ((SELECT) == ACMP_POSITIVE_SELECT_PIN0_5) || \
                                                     ((SELECT) == ACMP_POSITIVE_SELECT_PIN0_6) || \
                                                     ((SELECT) == ACMP_POSITIVE_SELECT_PIN0_7) || \
                                                     ((SELECT) == ACMP_POSITIVE_SELECT_PIN1_0))
/**
  * @}
  */ 

/** @defgroup ACMP_Output_State
  * @{
  */
#define	ACMP_OUTPUT_NORMAL                          ((uint32_t)0x00000000)
#define	ACMP_OUTPUT_INV                             ((uint32_t)0x00100000)

#define IS_ACMP_OUTPUT_STATE(STATE)    		       (((STATE) == ACMP_OUTPUT_NORMAL) || \
                                                    ((STATE) == ACMP_OUTPUT_INV))
/**
  * @}
  */ 

/** @defgroup ACMP_Hysteresis
  * @{
  */
#define	ACMP_HYSTERESIS_DISABLE                     ((uint32_t)0x00000000)
#define	ACMP_HYSTERESIS_15MV                        ((uint32_t)0x00000008)
#define	ACMP_HYSTERESIS_40MV                        ((uint32_t)0x0000000C)

#define IS_ACMP_HYSTERESIS(HYSTERESIS)    		    (((HYSTERESIS) == ACMP_HYSTERESIS_DISABLE)  || \
                                                     ((HYSTERESIS) == ACMP_HYSTERESIS_15MV)     || \
                                                     ((HYSTERESIS) == ACMP_HYSTERESIS_40MV))
/**
  * @}
  */ 

/** @defgroup ACMP_Clock_Div
  * @{
  */
#define IS_ACMP_CLKDIV(DIV)                         (((DIV) < 256))
/**
  * @}
  */ 

/** @defgroup ACMP_Sync_Compare_TRGS
  * @{
  */
#define	ACMP_SYNC_CMP_TRGS_NONE                     ((uint32_t)0x00000000)
#define	ACMP_SYNC_CMP_TRGS_PWM0                     ((uint32_t)0x00000001)
#define	ACMP_SYNC_CMP_TRGS_PWM1                     ((uint32_t)0x00000002)
#define	ACMP_SYNC_CMP_TRGS_PWM2                     ((uint32_t)0x00000003)

#define IS_ACMP_SYNC_CMP_TRGS(TRGS)    		       (((TRGS) == ACMP_SYNC_CMP_TRGS_NONE)   || \
                                                    ((TRGS) == ACMP_SYNC_CMP_TRGS_PWM0)   || \
                                                    ((TRGS) == ACMP_SYNC_CMP_TRGS_PWM1)   || \
                                                    ((TRGS) == ACMP_SYNC_CMP_TRGS_PWM2))
/**
  * @}
  */ 

/** @defgroup ACMP_Sync_Compare_TRGPOL
  * @{
  */
#define	ACMP_SYNC_CMP_TRGPOL_INVALID                ((uint32_t)0x00000001)
#define	ACMP_SYNC_CMP_TRGPOL_AVAILABILITY           ((uint32_t)0x00000000)

#define IS_ACMP_SYNC_CMP_TRGPOL(TRGPOL)             (((TRGPOL) == ACMP_SYNC_CMP_TRGPOL_INVALID)   || \
                                                     ((TRGPOL) == ACMP_SYNC_CMP_TRGPOL_AVAILABILITY))
/**
  * @}
  */ 

/** @defgroup ACMP_Filter1_Para
  * @{
  */
#define	ACMP_FILTER1_PARA_32                        ((uint32_t)0x00000000)
#define	ACMP_FILTER1_PARA_64                        ((uint32_t)0x00000001)
#define	ACMP_FILTER1_PARA_128                       ((uint32_t)0x00000002)
#define	ACMP_FILTER1_PARA_256                       ((uint32_t)0x00000003)
#define	ACMP_FILTER1_PARA_512                       ((uint32_t)0x00000004)
#define	ACMP_FILTER1_PARA_1024                      ((uint32_t)0x00000005)
#define	ACMP_FILTER1_PARA_2048                      ((uint32_t)0x00000006)
#define	ACMP_FILTER1_PARA_4096                      ((uint32_t)0x00000007)

#define IS_ACMP_FILTER1_PARA(PARA)                 (((PARA) == ACMP_FILTER1_PARA_32)    || \
                                                    ((PARA) == ACMP_FILTER1_PARA_64)    || \
                                                    ((PARA) == ACMP_FILTER1_PARA_128)   || \
                                                    ((PARA) == ACMP_FILTER1_PARA_256)   || \
                                                    ((PARA) == ACMP_FILTER1_PARA_512)   || \
                                                    ((PARA) == ACMP_FILTER1_PARA_1024)  || \
                                                    ((PARA) == ACMP_FILTER1_PARA_2048)  || \
                                                    ((PARA) == ACMP_FILTER1_PARA_4096))
/**
  * @}
  */ 

/** @defgroup ACMP_Filter2_Para
  * @{
  */
#define	ACMP_FILTER2_PARA_8                         ((uint32_t)0x00000000)
#define	ACMP_FILTER2_PARA_16                        ((uint32_t)0x00000001)
#define	ACMP_FILTER2_PARA_32                        ((uint32_t)0x00000002)
#define	ACMP_FILTER2_PARA_64                        ((uint32_t)0x00000003)
#define	ACMP_FILTER2_PARA_128                       ((uint32_t)0x00000004)
#define	ACMP_FILTER2_PARA_256                       ((uint32_t)0x00000005)
#define	ACMP_FILTER2_PARA_512                       ((uint32_t)0x00000006)
#define	ACMP_FILTER2_PARA_1024                      ((uint32_t)0x00000007)

#define IS_ACMP_FILTER2_PARA(PARA)                 (((PARA) == ACMP_FILTER2_PARA_8)     || \
                                                    ((PARA) == ACMP_FILTER2_PARA_16)    || \
                                                    ((PARA) == ACMP_FILTER2_PARA_32)    || \
                                                    ((PARA) == ACMP_FILTER2_PARA_64)    || \
                                                    ((PARA) == ACMP_FILTER2_PARA_128)   || \
                                                    ((PARA) == ACMP_FILTER2_PARA_256)   || \
                                                    ((PARA) == ACMP_FILTER2_PARA_512)   || \
                                                    ((PARA) == ACMP_FILTER2_PARA_1024))
/**
  * @}
  */ 

/** @defgroup ACMP_FilterDEB_Para
  * @{
  */
#define IS_ACMP_FILTERDEB_PARA(PARA)                ((PARA) < 0x100)
/**
  * @}
  */ 

/** @defgroup ACMP_FLT_Select
  * @{
  */
#define	ACMP_FLT_SELECT_CMP_OUT                     ((uint32_t)0x00000000)
#define	ACMP_FLT_SELECT_EXTERNAL_PIN                ((uint32_t)0x00000001)
#define IS_ACMP_FLT_SELECT(SELECT)                 (((SELECT) == ACMP_FLT_SELECT_CMP_OUT)     || \
                                                    ((SELECT) == ACMP_FLT_SELECT_EXTERNAL_PIN))
/**
  * @}
  */ 

/** @defgroup ACMP_PWMOut
  * @{
  */
#define	ACMP_PWMOUT_SELECT_PWM0                     ((uint32_t)0x00000030)
#define	ACMP_PWMOUT_SELECT_PWM1                     ((uint32_t)0x000000C0)
#define	ACMP_PWMOUT_SELECT_PWM2                     ((uint32_t)0x00000300)
#define IS_ACMP_PWMOUT_PWM(PWM)                    (((PWM) == ACMP_PWMOUT_SELECT_PWM0)   || \
                                                    ((PWM) == ACMP_PWMOUT_SELECT_PWM1)   || \
                                                    ((PWM) == ACMP_PWMOUT_SELECT_PWM2))
/**
  * @}
  */ 

/** @defgroup ACMP_PWMOutSelect
  * @{
  */
#define	ACMP_PWMOUT_SELECT_ALWAYS                   ((uint32_t)0x00000000)
#define	ACMP_PWMOUT_SELECT_ACMP0                    ((uint32_t)0x00000001)
#define	ACMP_PWMOUT_SELECT_ACMP1                    ((uint32_t)0x00000002)
#define IS_ACMP_PWMOUT_SELECT(SELECT)              (((SELECT) == ACMP_PWMOUT_SELECT_ALWAYS) || \
                                                    ((SELECT) == ACMP_PWMOUT_SELECT_ACMP0)  || \
                                                    ((SELECT) == ACMP_PWMOUT_SELECT_ACMP1))
/**
  * @}
  */ 

/** @defgroup ACMP_RES_DIV_SOURCE
  * @{
  */
#define	ACMP_RES_DIV_SOURCE_VDD                     ((uint32_t)0x00000000)
#define	ACMP_RES_DIV_SOURCE_ADC_VREF                ((uint32_t)0x00000001)
#define IS_ACMP_RES_DIV_SOURCE(SOURCE)             (((SOURCE) == ACMP_RES_DIV_SOURCE_VDD) || \
                                                    ((SOURCE) == ACMP_RES_DIV_SOURCE_ADC_VREF))
/**
  * @}
  */ 

/** @defgroup ACMP_RES_DIV
  * @{
  */
#define IS_ACMP_RES_DIV(DIV)                        ((DIV) < 64)
/**
  * @}
  */ 

/** 
  * @brief  Configuration Edge Action enumeration  
  */
#define	ACMP_IT_ACTION_FALLING                      ((uint32_t)0x00010000)
#define	ACMP_IT_ACTION_RISING                       ((uint32_t)0x00020000)
#define	ACMP_IT_ACTION_DOUBLE                       ((uint32_t)0x00000000)
#define IS_ACMP_IT_ACTION(ACTION)                  (((ACTION) == ACMP_IT_ACTION_FALLING)  || \
                                                    ((ACTION) == ACMP_IT_ACTION_RISING)   || \
                                                    ((ACTION) == ACMP_IT_ACTION_DOUBLE))
/**
  * @}
  */

/** @defgroup OPA_GAIN
  * @{
  */
#define	OPA_EXT_RES                                 ((uint32_t)0x00000000)
#define	OPA_GAIN_1X                                 ((uint32_t)0x00000001)
#define	OPA_GAIN_2X                                 ((uint32_t)0x00000002)
#define	OPA_GAIN_3X                                 ((uint32_t)0x00000003)
#define	OPA_GAIN_4X                                 ((uint32_t)0x00000004)
#define	OPA_GAIN_6X                                 ((uint32_t)0x00000005)
#define	OPA_GAIN_8X                                 ((uint32_t)0x00000006)
#define	OPA_GAIN_10X                                ((uint32_t)0x00000007)
#define IS_OPA_GAIN(GAIN)                          (((GAIN) == OPA_EXT_RES) || \
                                                    ((GAIN) == OPA_GAIN_1X) || \
                                                    ((GAIN) == OPA_GAIN_2X) || \
                                                    ((GAIN) == OPA_GAIN_3X) || \
                                                    ((GAIN) == OPA_GAIN_4X) || \
                                                    ((GAIN) == OPA_GAIN_6X) || \
                                                    ((GAIN) == OPA_GAIN_8X) || \
                                                    ((GAIN) == OPA_GAIN_10X))
/**
  * @}
  */ 





/**
  * @}
  */ 

/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */ 
void ACMP_DeInit(void);
void ACMP_Init(uint32_t ACMPx, ACMP_InitTypeDef* ACMP_InitStruct);
void ACMP_Cmd(uint32_t ACMPx, FunctionalState NewState);
void ACMP_Filter1Config(uint32_t ACMPx, uint32_t Para, FunctionalState NewState);
void ACMP_Filter2Config(uint32_t ACMPx, uint32_t Para, FunctionalState NewState);
void ACMP_FilterDEBConfig(uint32_t ACMPx, uint32_t Para, FunctionalState NewState);
void ACMP_FLTSelect(uint32_t ACMPx, uint32_t Select);
void ACMP_PWMOutSelect(uint32_t PWM, uint32_t Select);
FlagStatus ACMP_GetResult(uint32_t ACMPx);
void ACMP_RESDIVConfig(uint32_t Source, uint32_t Div);
void ACMP_RESDIVCmd(FunctionalState NewState);
void ACMP_SyncCompareConfig(uint32_t ACMPx, uint32_t TRGS, uint32_t TRGPOL);
void ACMP_ITConfig(uint32_t ACMPx, uint32_t ACMP_IT, FunctionalState NewState);
ITStatus ACMP_GetITStatus(uint32_t ACMPx);
void ACMP_ClearITPendingBit(uint32_t ACMPx);

void ACMP_SelectOPA(uint32_t ACMPx, uint32_t OPAx, FunctionalState NewState);
void OPA_Config(uint32_t OPAx, uint32_t Gain);
void OPA_Cmd(uint32_t OPAx, FunctionalState NewState);

#ifdef __cplusplus
}
#endif

#endif /*__W32F006_ACMP_H */

/**
  * @}
  */ 

/**
  * @}
  */ 

/************************ (C) COPYRIGHT WeiLink Technology *****END OF FILE****/

